const app = getApp()
import { openPage } from '../../utils/map/open'
import {chineseWeek} from '../../utils/util'
Page({
  data: {
    imgurl: app.globalData.imgurl,
    touchStartTime: 0, // 触摸开始时间
    touchEndTime: 0, // 触摸结束时间
    lastTapTime: 0, // 最后一次单击事件点击发生时间
  },
  onLoad(option) {
    let { s_id } = option
    this._getDetail(s_id)
    this._getCont(s_id)
    this._getTime(s_id)
    this.setData({
      s_id,
    })
  },

  // 获取详情
  async _getDetail(s_id) {
    let { code, data } = await wx.requestAsync({
      url: '/shop/detail',
      data: {
        s_id,
      },
    })
    if (code == 0) {
      this.setData(data)
    }
  },
  // 获取内容
  async _getCont(s_id) {
    let { code, data } = await wx.requestAsync({
      url: '/shop/content',
      data: {
        s_id,
        type: 1,
      },
    })
    if (code == 0) {
      this.setData({
        content: data,
      })
    }
  },
  async _getTime(s_id) {
    let { code, data } = await wx.requestAsync({
      url: '/shop/time',
      data: {
        s_id,
      },
    })
    if (code == 0) {
      let time = data.map(item => {
        item.week_start = chineseWeek(item.week_start)
        item.week_end = chineseWeek(item.week_end)
        return item
      })
      this.setData({
        time,
      })
    }
  },

  mytouchstart({ timeStamp }) {
    this.setData({
      touchStartTime: timeStamp,
    })
  },
  mytouchend({ timeStamp }) {
    this.setData({
      touchEndTime: timeStamp,
    })
  },

  _handleLeft({ timeStamp }) {
    const {
      touchEndTime,
      touchStartTime,
      lastTapTime,
      p_name,
      c_name,
      a_name,
      address,
    } = this.data
    // 控制点击事件在350ms内触发，加这层判断是为了防止长按时会触发点击事件
    if (touchEndTime - touchStartTime < 350) {
      // 更新最后一次点击时间
      this.setData({
        lastTapTime: timeStamp,
      })
      // 如果两次点击时间在300毫秒内，则认为是双击事件
      if (timeStamp - lastTapTime > 300) {
        // do something 点击事件具体执行那个业务
        openPage({ p_name, c_name, a_name, address }, this)
      }
    }
  },
  _handleRight() {
    const { phone } = this.data
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  // 拼组列表
  _toGame() {
    let { s_id } = this.data
    wx.navigateTo({
      url: '/pages/reservationList/reservationList?s_id=' + s_id,
    })
  },
  // 亲子
  _toParentgame() {
    let { s_id } = this.data
    wx.navigateTo({
      url: '/pages/parentgame/parentgame?s_id=' + s_id,
    })
  },
})
